package com.weijianhuawen.wjblog.admin.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

/**
 * @version: java version 8
 * @Author: weijianhuawen
 * @description: 线程池配置
 * @date: 2024-11-01 13:30
 */

@Configuration
@EnableAsync
public class ThreadPoolConfig {
    // 创建线程池对象，并交给spring容器管理
    @Bean
    public ThreadPoolTaskExecutor threadPoolTaskExecutor() {
        ThreadPoolTaskExecutor threadPoolTaskExecutor = new ThreadPoolTaskExecutor();

        // 设置线程池参数
        threadPoolTaskExecutor.setCorePoolSize(10);
        threadPoolTaskExecutor.setMaxPoolSize(20);
        threadPoolTaskExecutor.setQueueCapacity(128);
        threadPoolTaskExecutor.setThreadNamePrefix("WJBlogThreadPool-"); // 线程前缀名
        threadPoolTaskExecutor.initialize();// 初始化
        return threadPoolTaskExecutor;
    }
}
